﻿#region Imports
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Input;
using BulkRenamer.Common.Models;
using BulkRenamer.Util.Util;
using CommonUtilities.Commands;
using CommonUtilities.Enums;
using CommonUtilities.Extensions;
using CommonUtilities.Info;
using CommonUtilities.Util;
using ResourcesUtilities = CommonUtilities.Properties.Resources;
#endregion Imports

namespace BulkRenamer.App.WPF.ViewModels
{
    public class MainViewModel : BaseViewModel
    {
        #region Declarations

        #endregion Declarations

        #region Properties
        public string AppName { get { return AppInfo.ApplicationTitle; } }

        private ObservableCollection<FileDetails> allFileDetails;
        public ObservableCollection<FileDetails> AllFileDetails
        {
            get { return allFileDetails; }
            set
            {
                allFileDetails = value;
                RaisePropertyChanged("AllFileDetails");

                RaisePropertyChanged("IsOutputEnabled");
                RaisePropertyChanged("IsSuggestEnabled");
                RaisePropertyChanged("IsEditorEnabled");
            }
        }

        private ObservableCollection<FileDetails> allFilteredFileDetails;
        public ObservableCollection<FileDetails> AllFilteredFileDetails
        {
            get { return allFilteredFileDetails; }
            set { allFilteredFileDetails = value; RaisePropertyChanged("AllFilteredFileDetails"); }
        }

        public int RecCount { get; set; }

        public int SelCount { get; set; }

        private FileDetails selectedFileDetails;
        public FileDetails SelectedFileDetails
        {
            get { return selectedFileDetails; }
            set { selectedFileDetails = value; RaisePropertyChanged("SelectedFileDetails"); }
        }

        public string LogPath { get; set; }

        private string selectedBasePath;
        public string SelectedBasePath
        {
            get { return selectedBasePath; }
            set
            {
                selectedBasePath = value;
                RaisePropertyChanged("SelectedBasePath");

                RaisePropertyChanged("IsLoadEnabled");
            }
        }

        public string UpdatePatternText { get; set; }

        public string UpdateAppendText { get; set; }

        public string UpdateReplaceText { get; set; }

        public bool AddSeparator { get; set; }

        public bool TakeSuggested { get; set; }

        private ObservableCollection<ExtnFilters> allFilters;
        public ObservableCollection<ExtnFilters> AllFilters
        {
            get { return allFilters; }
            set { allFilters = value; RaisePropertyChanged("AllFilters"); }
        }

        public string FilterText
        {
            get
            {
                return AllFilters._Where(fltr => (bool)fltr.Value)._OrderBy(fltr => fltr.Id)
                    ._Select(fltr => fltr.Id).AppendText(",").Coalesce(ResourcesUtilities.Const_NotAvailable);
            }
        }

        public bool IsMidChecked { get; set; }

        public string DataMgmtPath { get; set; }


        private bool? isAllFilters;
        public bool? IsAllFilters
        {
            get { return isAllFilters; }
            set
            {
                isAllFilters = value;
                RaisePropertyChanged("IsAllFilters");

                if (skipFilter) return;

                if (!isAllFilters.HasValue)
                    ApplyExtnFilter(-1);
                else
                    ApplyExtnFilter("All");
            }
        }

        private ObservableCollection<PathHistory> allPathHistory = new ObservableCollection<PathHistory>();
        public ObservableCollection<PathHistory> AllPathHistory
        {
            get { return allPathHistory; }
            set { allPathHistory = value; RaisePropertyChanged("AllPathHistory"); }
        }

        /// <summary>
        /// Information on files deleted (soft delete) from the File list
        /// </summary>
        public ObservableCollection<FileDeletionDetails> AllDeletedIds { get; private set; }

        public bool IsInit { get; set; }

        public bool IsUsingComboText { get; set; }

        public string SelectedBasePath_AutoSugg { get; set; }

        public bool IsNavigating { get; set; }

        public bool IsAutoLoadChecked { get; set; }

        public string SubDirectoryCount { get; set; }

        public bool IsAutoLoad { get; set; }

        public int SuggestCount { get; set; }

        private string deleteButtonText;
        public string DeleteButtonText
        {
            get { return deleteButtonText; }
            set { deleteButtonText = value; RaisePropertyChanged("DeleteButtonText"); }
        }

        public bool IsFetchDirUpEnabled { get; set; }
        public bool IsFetchDirDownEnabled { get; set; }
        public bool IsFetchDirPrevEnabled { get; set; }
        public bool IsFetchDirNextEnabled { get; set; }

        public ICommand BrowseLogPathCommand { get; private set; }
        public ICommand BrowseBasePathCommand { get; private set; }
        public ICommand LoadFilesCommand { get; private set; }
        public ICommand FetchDirectoryCommand { get; private set; }
        public ICommand ApplyExtnFilterCommand { get; private set; }
        public ICommand DeleteFilesCommand { get; private set; }
        public ICommand SuggestNamesCommand { get; private set; }
        public ICommand UpdateFilesCommand { get; private set; }
        public ICommand UpdateDeleteButtonTextCommand { get; private set; }
        public ICommand OpenFileDetailsCommand { get; private set; }
        public ICommand TestCommand { get; private set; }
        #endregion Properties

        #region Constructors
        public MainViewModel()
        {
            IsInit = true;

            BrowseLogPathCommand = new RelayCommand((parameter) => { BrowseLogPath(); });
            BrowseBasePathCommand = new RelayCommand((parameter) => { BrowseBasePath(); });
            LoadFilesCommand = new RelayCommand((parameter) => { LoadFiles(); });
            FetchDirectoryCommand = new RelayCommand<string>((parameter) => { FetchDirectory(parameter); });
            ApplyExtnFilterCommand = new RelayCommand<object>((parameter) => { ApplyExtnFilter(parameter); });
            DeleteFilesCommand = new RelayCommand((parameter) => { DeleteFiles(); });
            SuggestNamesCommand = new RelayCommand<object>((parameter) => { SuggestNames(parameter); });
            UpdateFilesCommand = new RelayCommand((parameter) => { UpdateFileNames(); });
            UpdateDeleteButtonTextCommand = new RelayCommand<string>((parameter) => { UpdateDeleteButtonText(parameter); });
            OpenFileDetailsCommand = new RelayCommand<FileDetails>((parameter) => { OpenFileDetails(parameter); });
            TestCommand = new RelayCommand((parameter) => { TestMethod(); });

            //AllPathHistory = new ObservableCollection<PathHistory>();
            AllDeletedIds = new ObservableCollection<FileDeletionDetails>();
            //AllExportExtn = IdNameValueMember.GetMembersFromSettings(Program.BulkRenamerSettings["ExportExtensions"]);
            //AllFileExtenstions = IdNameValueMember.GetMembersFromSettings(Program.BulkRenamerSettings["FileExtensions"]);













            IsUsingComboText = true;
            IsAutoLoad = true;

            UpdateDeleteButtonText(null);

            SelectedBasePath = @"S:\_series\DOWN\House of Cards\House.Of.Cards.2013.S01.Season.1.720p.BluRay.x264.anoXmous";
            //SelectedBasePath = @"E:\_DONE\Untamed Americas";
            //SelectedBasePath = @"E:\_DONE\missing_DONE\_GRIFFITH\Liar Liar (1997)";

            LogPath = @"C:\Users\rhythm divine\Documents\Visual Studio 2010\Projects\BulkRenamer\OUTPUT\Logs\log_20130512_024710.csv";

            StopAndPerform(ref      skipFilter, () => { IsAllFilters = false; });

            IsInit = false;
        }

        private void TestMethod()
        {
            MessageBox.Show(AllDeletedIds._Select(del => "{0}.{1}".FormatTextFromParams(del.FileDetails.NameOrg, del.FileDetails.FileExtn)).AppendText(Environment.NewLine));
        }
        #endregion Constructors

        #region Events

        #endregion Events

        #region Methods
        private void BrowseLogPath()
        {
            MessageBox.Show("YET TO BE IMPLEMENTED");
        }

        /// <summary>
        /// 
        /// Shadow of : btnBrowseBasePath_Click(object sender, EventArgs e)
        /// </summary>
        private void BrowseBasePath()
        {
            //if (Form.ModifierKeys == Keys.Control)
            //{
            //    frmPathHistorySelector pathHistSelector = new frmPathHistorySelector(AllPathHistory);
            //    pathHistSelector.ShowDialog(this);
            //    if (pathHistSelector.DialogResult == DialogResult.OK) LoadPath(sender, e, pathHistSelector.SelectedPath);
            //
            //    pathHistSelector.Dispose();
            //    pathHistSelector = null;
            //    return;
            //}

            //chkAnyExtn.Enabled = cmbExtnFilters.Enabled = btnLoadExtn.Enabled = false;
            FolderBrowserDialog dlgFolderBrowser = new FolderBrowserDialog()
            {
                Description = "Select base directory..",
                ShowNewFolderButton = false,
                RootFolder = Environment.SpecialFolder.Desktop,
            };

            if (SelectedBasePath.ValidatePath(ePathValidation.Directory))
                dlgFolderBrowser.SelectedPath = SelectedBasePath;
            //else dlgFolderBrowser.RootFolder = Environment.SpecialFolder.Desktop;

            if (dlgFolderBrowser.ShowDialog() == DialogResult.OK)
                LoadPath(dlgFolderBrowser.SelectedPath);
        }

        private void LoadPath(string basePath)
        {
            if (IsUsingComboText) SelectedBasePath = basePath;
            else SelectedBasePath_AutoSugg = basePath;
            if (IsAutoLoad) LoadFiles();
        }

        /// <summary>
        /// 
        /// Shadow of : btnFetchDirectory_Click(object sender, EventArgs e)
        /// </summary>
        /// <param name="parameter"></param>
        private void FetchDirectory(string parameter)
        {
            eFetchTypes fetchType = Utilities.GetEnumFromControl<eFetchTypes>(parameter, "btnFetchDir", "mnuFetchDir");
            FetchDirectory(fetchType);
            if (IsUsingComboText) EventNotifier.BasePathFocus(null); // else txtBasePath_AutoSugg.Focus();
        }

        /// <summary>
        /// Fetches directory based on specified direction
        /// </summary>
        /// <param name="fetchType">Fetch type</param>
        /// <param name="sender">Sender</param>
        /// <param name="e">EventArgs</param>
        private void FetchDirectory(eFetchTypes fetchType)
        {
            string tmpSelectedBasePath = SelectedBasePath;
            if (EvaluateDirectory(fetchType, SelectedBasePath, ref tmpSelectedBasePath))
            {
                IsNavigating = true; if (IsUsingComboText) SelectedBasePath = tmpSelectedBasePath; else SelectedBasePath_AutoSugg = tmpSelectedBasePath; IsNavigating = false;
                if (IsAutoLoadChecked) LoadFiles();
            }
        }

        /// <summary>
        /// Evaluates a directory for Prev/Next/Up/Down functions
        /// </summary>
        /// <param name="fetchType">Fetch type</param>
        /// <param name="srcPath">Path to validate against</param>
        /// <param name="destPath">Path (updated, only when valid)
        /// <para>Note: this passed ByRef</para></param>
        /// <returns></returns>
        public bool EvaluateDirectory(eFetchTypes fetchType, string srcPath, ref string destPath)
        {
            if (!srcPath.ValidatePath(ePathValidation.Directory)) return false;

            ObservableCollection<string> allDirectories = new ObservableCollection<string>();
            int currDirectoryIndex = -1;
            bool pathValidations = false;
            bool result = false;

            if (!srcPath.Contains(Path.DirectorySeparatorChar) && !srcPath.IsNullOrEmpty())
                srcPath += Path.DirectorySeparatorChar;

            if (fetchType != eFetchTypes.All)
            {
                destPath = srcPath;
                pathValidations = srcPath.ValidatePath(ePathValidation.Directory) && srcPath != Path.DirectorySeparatorChar.ToString();

                if (pathValidations)
                {
                    if (fetchType == eFetchTypes.Prev || fetchType == eFetchTypes.Next)
                    {
                        if (!Directory.GetParent(srcPath).IsNull())
                            allDirectories = Utilities.GetValidDirectories(Directory.GetParent(srcPath).FullName).ToObservableCollection();
                        else
                            allDirectories = DriveInfo.GetDrives().Where(drv => drv.IsReady)
                                .Select(drv => drv.RootDirectory.Root.FullName).ToObservableCollection();

                        currDirectoryIndex = allDirectories.IndexOf(srcPath);
                    }
                }
            }

            string tmpPath = "";
            string sLocationInfo = "";
            //CUtil_DirectionButtons btnFetchDir = null;
            //ToolStripMenuItem mnuFetchDir = null;

            switch (fetchType)
            {
                case eFetchTypes.Up:
                case eFetchTypes.Down:
                case eFetchTypes.Prev:
                case eFetchTypes.Next:
                    fetchType._GetValues()._ForEach(f =>
                    {
                        var prop = this.GetType().GetProperty("IsFetchDir{0}Enabled".FormatTextFromParams(f));
                        if (!prop.IsNull()) prop.SetValue(this, fetchType == f, null);
                    });
                    break;

                case eFetchTypes.All:
                    foreach (eFetchTypes ftype in Enum.GetValues(typeof(eFetchTypes)).Cast<eFetchTypes>())
                        if (ftype != fetchType) EvaluateDirectory(ftype, SelectedBasePath, ref destPath);
                    break;

                default:
                    result = false;
                    break;
            }

            if (fetchType != eFetchTypes.All)
            {
                tmpPath = srcPath.GetDirectoryByDirection(fetchType, out result, out sLocationInfo, allDirectories);
                if (fetchType == eFetchTypes.Prev || fetchType == eFetchTypes.Next) SubDirectoryCount = sLocationInfo;
                // mnuFetchDir.Enabled = btnFetchDir.IsEnabled = result = (pathValidations && result);
                if (result) destPath = tmpPath;
            }

            return result;
        }

        private ObservableCollection<FileDetails> GetValidFileList(bool? ignoreExtnFilters) // fetchUnfiltered
        {
            if (IsAllFilters == true)
                return AllFileDetails._Where(fdet => !AllDeletedIds._Select(del => del.FileDetails.FileId)._Contains(fdet.FileId))
                    ._OrderBy(fdet => fdet.FileId).ToObservableCollection();
            else
            {
                return AllFileDetails._Where(fdet => !AllDeletedIds._Select(del => del.FileDetails.FileId)._Contains(fdet.FileId)
                        && AllFilters._Where(fltr => (bool)fltr.Value)._Select(fltr => fltr.Id).Contains(fdet.FileExtn))
                    ._OrderBy(fdet => fdet.FileId).ToObservableCollection();
            }
        }

        private void LoadFiles()
        {
            SuggestCount = 0;
            AllFileDetails = new ObservableCollection<FileDetails>();
            //cmnuDeleteSelection.Enabled = btnDelete.Enabled = btnExport.Enabled = false;

            if (Directory.Exists(SelectedBasePath))
            {
                ObservableCollection<string> allFileNames = Utilities.GetValidFiles(SelectedBasePath)
                    //.Where(fpath => chkAnyExtn.Checked || Path.GetExtension(fpath).TrimStart('.') == SelectedExtn)
                    .OrderBy(fpath => Path.GetFileName(fpath)).ToObservableCollection();

                ObservableCollection<FileDetails> allFileDetails = new ObservableCollection<FileDetails>();
                allFileNames.ForEach(fileName => allFileDetails.Add(FileDetails.CreateItem(fileName, true, "")));

                allFileDetails = allFileDetails.AddCollectionIndex<FileDetails>("FileId").ToObservableCollection();
                AllFileDetails = allFileDetails.OrderBy(fdet => fdet.FileId).ToObservableCollection();

                if (AllDeletedIds.IsLinqIterable<FileDeletionDetails>(true)) AllDeletedIds.Clear();
                else AllDeletedIds = new ObservableCollection<FileDeletionDetails>();

                AllFilters = AllFileDetails._Select(fdet => fdet.FileExtn).Distinct()
                    ._OrderBy()._Select(extn => new ExtnFilters(extn)).ToObservableCollection();

                StopAndPerform(ref skipFilter, () => { IsAllFilters = true; });

                ApplyExtnFilter("All");

                RaisePropertyChanged("IsNameListEnabled");

                /*
                chkExtnFilterSelMode.ThreeState = false;
                chkExtnFilterSelMode.CheckState = CheckState.Checked;
                ReloadList(true);

                ClearAll();
                DefineRange(null);

                ObservableCollection<FileDetails> validFiles = GetValidFileList(false);
                cmnuDeleteSelection.Enabled = lstFileNames.Enabled = btnDelete.Enabled = btnExport.Enabled = btnUpdateFiles.Enabled = validFiles.Any();
                mnuSuggest.Enabled = grpOutput.Enabled = (validFiles.Count() > 1);
                IsMidChecked = false;

                grpOutput.Controls.Cast<Control>().ForEach(ctrl => ctrl.Enabled = (ctrl.Name != btnUpdateFiles.Name) ? grpOutput.Enabled : ctrl.Enabled);

                chkAddSeparator_CheckChanged(sender, e);

                if (validFiles.Any()) LoadFileDetails(0);
                */

                if (AllFileDetails.Any()) AddPathToHistory();
            }
        }

        private void AddPathToHistory()
        {
            string path = SelectedBasePath.Trim(Path.DirectorySeparatorChar);
            if (AllPathHistory.Select(hist => hist.Path).Contains(path))
                AllPathHistory.Where(hist => hist.Path == path).First().LastAccessed = DateTime.Now;
            else
                AllPathHistory.Add(new PathHistory { Path = path });
        }

        bool skipFilter = false;

        private void ApplyExtnFilter(object parameter)
        {
            //if (IsInit)
            //{
            //    skipFilter = true;
            //    if (!IsAllFilters.Coalesce(false)) IsAllFilters = true;
            //    skipFilter = false;
            //}

            if (parameter.ToString() == "All")
            {
                AllFilters._ForEach(extn => extn.Value = IsAllFilters.Coalesce(false));
                ApplyExtnFilter(-1);
            }
            else
            {
                StopAndPerform(ref skipFilter, () =>
                {
                    if (AllFilters._Select(flt => (bool)flt.Value).Distinct().GetCount() > 1) IsAllFilters = null;
                    else IsAllFilters = AllFilters._Select(flt => (bool)flt.Value).First();
                });

                AllFilteredFileDetails = GetValidFileList(IsAllFilters);
                RaisePropertyChanged("FilterText");
            }
        }

        private void DeleteFiles()
        {
            DeleteFile(GetValidFileList(false).Where(fdet => fdet.IsNameSelected).ToObservableCollection(), DateTime.Now);
        }

        private void DeleteFile(ObservableCollection<FileDetails> fileDetails, DateTime timeStamp)
        {
            fileDetails._ForEach(fdet => DeleteFile(fdet, timeStamp));
        }

        private void DeleteFile(FileDetails fileDetails, DateTime timeStamp)
        {
            if (!fileDetails.IsNull())
            {
                AllDeletedIds.Add(new FileDeletionDetails { FileDetails = fileDetails, TimeStamp = timeStamp });

                var validFiles = GetValidFileList(false);
                IsExportEnabled = (validFiles.Any()); RaisePropertyChanged("IsDeleteEnabled");
                if (!validFiles.Any()) ClearAll();
            }
        }

        private void ClearAll()
        {
            ClearEditor();

            IsMidChecked = false;
            IsExportEnabled = IsUpdateFilesEnabled = GetValidFileList(false).Any();
            RaisePropertyChanged("IsNameListEnabled"); RaisePropertyChanged("IsOutputEnabled"); RaisePropertyChanged("IsDeleteEnabled");
            LTrimLen = RTrimLen = LTrimMax = RTrimMax = LTrimMin = RTrimMin = custLTrimLength = custRTrimLength = 0;
            UpdatePatternText = UpdateReplaceText = UpdateAppendText = "";
            dictTrimChange[KEY_LTrimChange] = dictTrimChange[KEY_RTrimChange] = 0;
        }

        private void ClearEditor()
        {
            SelectedFileDetails = new FileDetails();
            IsAutoUpdate = true;
            RaisePropertyChanged("IsEditorEnabled");
        }

        private bool isAutoUpdate;
        public bool IsAutoUpdate
        {
            get { return isAutoUpdate; }
            set { isAutoUpdate = value; RaisePropertyChanged("IsAutoUpdate"); }
        }

        public bool IsDeleteEnabled { get { return GetValidFileList(false)._Where(fdet => fdet.IsNameSelected).Any(); } }

        private bool isExportEnabled;
        public bool IsExportEnabled
        {
            get { return isExportEnabled; }
            set { isExportEnabled = value; RaisePropertyChanged("IsExportEnabled"); }
        }

        /*
        {
            ObservableCollection<FileDetails> validFiles = GetValidFileList(false);

            if (validFiles.HasCount(0))
            { MessageBoxUtil.Show(Program.IsDebug, "Validation: No more files to delete!\t", "No files.."); return; }

            if (lstFileNames.SelectedItems.Count == 0) return;

            int selectedFileIndex = -1;
            int minId = validFiles.Select(fdet => fdet.FileId).Min();

            DateTime timeStamp = DateTime.Now;
            if (lstFileNames.SelectedItems.Count == 1) // Performance improvement only, ELSE block is generic
                DeleteFile((FileDetails)lstFileNames.SelectedItems[0], timeStamp, true); // Delete item & update list
            else
                // RKD : removed foreach
                //for each (FileDetails fdet in lstFileNames.SelectedItems)
                //    DeleteFile(fdet, timeStamp, false); // Delete item & update list
                lstFileNames.SelectedItems.Cast<FileDetails>().ForEach(fdet => DeleteFile(fdet, timeStamp, false));

            // Refresh file list
            validFiles = GetValidFileList(false);

            // Clear editor if deleted item is in editor
            if (!txtId.Text.IsNullOrEmpty())
                if (!validFiles.Where(fdet => fdet.FileId == Convert.ToInt32(txtId.Text)).Any())
                    ClearEditor();

            if (validFiles.Any())
            {
                // Set selection
                int minDelId = AllDeletedIds.Where(del => del.TimeStamp == timeStamp).Select(del => del.FileDetails.FileId).Min();
                selectedFileIndex = (minDelId <= minId)
                    ? validFiles.Select(fdet => fdet.FileId).Min()
                    : validFiles.Where(fdet => fdet.FileId < minDelId).Select(fdet => fdet.FileId).Max();
                lstFileNames.SelectedItems.Clear();
                lstFileNames.DataSource = validFiles;
                lstFileNames.SelectedItem = validFiles.Where(fdet => fdet.FileId == selectedFileIndex).FirstOrDefault();
                selectedFileIndex = lstFileNames.SelectedIndex;

                // Refresh and load
                if (validFiles.Where(fdet => fdet.FileId == (!txtId.Text.IsNullOrEmpty() ? Convert.ToInt32(txtId.Text) : 0)).HasCount(0))
                    LoadFileDetails(selectedFileIndex);

                mnuSuggest.Enabled = grpOutput.Enabled = (validFiles.Count() > 1);
            }
            else
                btnUpdateFiles.Enabled = false; // No need to clear editor; handled while deleting file with ClearAll

            // REQ-##123 : Update LTrim max value on delete of file
            UpdateMaxTrimRange(); DefineRange(null);
        }

        private void DeleteFile(FileDetails fileDetails, DateTime timeStamp, bool reloadList)
        {
            if (!fileDetails.IsNull())
            {
                AllDeletedIds.Add(new FileDeletionDetails { Id = fileDetails.FileId, TimeStamp = timeStamp });

                ObservableCollection<FileDetails> validFiles = GetValidFileList(false);
                cmnuDeleteSelection.Enabled = btnDelete.Enabled = btnExport.Enabled = (validFiles.Any());
                if (!validFiles.Any()) ClearAll();

                if (reloadList) ReloadList(true, true);
            }
        }

        private void DeleteFile(int fileId, DateTime timeStamp, bool reloadList)
        {
            FileDetails fileDetails = AllFileDetails.Where(fdet => fdet.FileId == fileId).First();
            DeleteFile(fileDetails, timeStamp, reloadList);
        }

        private void DeleteFile(IEnumerable<int> fileIds, DateTime timeStamp, bool reloadList)
        {
            IEnumerator<int> item = fileIds.GetEnumerator();
            item.Reset();

            while (item.MoveNext()) { DeleteFile(item.Current, timeStamp, reloadList); }
        }

        private void ReloadList(bool refreshFilters, bool restoreFilters = false)
        {
            if (refreshFilters) RefreshFilters(restoreFilters);

            IsReloading = true;
            ObservableCollection<FileDetails> allFileDetails = GetValidFileList(false).ToObservableCollection();
            lstFileNames.DataSource = allFileDetails;
            RefreshCount(); UpdateMaxTrimRange();
            IsReloading = false;

            if (refreshFilters && allFileDetails.Any()) LoadFileDetails(0);
        }
        */

        private void SuggestNames(object parameter)
        {
            MessageBox.Show("YET TO BE IMPLEMENTED");
        }

        private void UpdateFileNames()
        {
            MessageBox.Show("YET TO BE IMPLEMENTED");
        }

        private void UpdateDeleteButtonText(string parameter)
        {
            long count = AllFileDetails._Where(fdet => fdet.IsNameSelected).GetCount();
            DeleteButtonText = ("Delete" + (parameter == "Enter" ? (count > 0 ? " ({0})" : "") : "")).FormatTextFromParams(count);
        }

        private void OpenFileDetails(FileDetails parameter)
        {
            SelectedFileDetails = parameter;
        }

        public void StopAndPerform(ref bool isLoadingProperty, Action action)
        {
            isLoadingProperty = true;
            action();
            isLoadingProperty = false;
        }
        #endregion Methods
























        public bool IsEditorEnabled { get { return GetValidFileList(false)._None() || !SelectedFileDetails.IsNull(); } }

        public bool IsSuggestEnabled { get { return GetValidFileList(false).Any(); } }

        public bool IsOutputEnabled { get { return GetValidFileList(false).Any(); } }

        public bool IsNameListEnabled { get { return GetValidFileList(false).Any(); } }

        private bool isUpdateFilesEnabled;
        public bool IsUpdateFilesEnabled
        {
            get { return isUpdateFilesEnabled; }
            set { isUpdateFilesEnabled = value; RaisePropertyChanged("IsUpdateFilesEnabled"); }
        }

        private int _LTrimLen;
        public int LTrimLen
        {
            get { return _LTrimLen; }
            set { _LTrimLen = value; RaisePropertyChanged("LTrimLen"); }
        }

        private int _RTrimLen;
        public int RTrimLen
        {
            get { return _RTrimLen; }
            set { _RTrimLen = value; RaisePropertyChanged("RTrimLen"); }
        }

        private int _LTrimMax;
        public int LTrimMax
        {
            get { return _LTrimMax; }
            set { _LTrimMax = value; RaisePropertyChanged("LTrimMax"); }
        }

        private int _RTrimMax;
        public int RTrimMax
        {
            get { return _RTrimMax; }
            set { _RTrimMax = value; RaisePropertyChanged("RTrimMax"); }
        }

        private int _LTrimMin;
        public int LTrimMin
        {
            get { return _LTrimMin; }
            set { _LTrimMin = value; RaisePropertyChanged("LTrimMin"); }
        }

        private int _RTrimMin;
        public int RTrimMin
        {
            get { return _RTrimMin; }
            set { _RTrimMin = value; RaisePropertyChanged("RTrimMin"); }
        }

        public bool IsLoadEnabled { get { return SelectedBasePath.ValidatePath(ePathValidation.Directory); } }

        private int custLTrimLength;
        private int custRTrimLength;
        Dictionary<string, int> dictTrimChange = new Dictionary<string, int>();
        const string KEY_LTrimChange = "LTrimChange";
        const string KEY_RTrimChange = "RTrimChange";

        /*
        private int suggLPatternLen;
        private int suggRPatternLen;
       
        private string btnSuggestNames_Name;

        public bool SupressSuggestion { get; set; }

        private string txtAppend_Name = "Append";
        private string txtReplace_Name = "Replace";
        private bool chkAnyExtn_Checked = true;

        public bool txtPattern_Enabled { get; set; }

        public bool txtAppend_Enabled { get; set; }

        public bool txtReplace_Enabled { get; set; }
        */
    }
}
